﻿Imports Control_Vuelos_BL
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraGrid.Views.Grid

Public Class frmConsultarViajeXTrabajador
    Inherits frmBaseMantenimiento

    Private WithEvents printableComponentLink1 As New PrintableComponentLink()
    Private Const ImageDir As String = "Resources\"
    Private ReadOnly Images As New Hashtable()
    ReadOnly oPasajero As New PasajeroBL()


    Private Sub frmConsultarViajeXTrabajador_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
        SG_Control_Vuelos_Main.RibbonPageGroup1.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup2.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup3.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup4.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup5.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup6.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup7.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup9.Visible = True
    End Sub

    Private Sub frmConsultarViajeXTrabajador_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        BarBtnAgregar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnModificar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnEliminar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnCancelar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnGrabar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        prl_Refresh()
        AddHandler BarBtnImprimir.ItemClick, AddressOf prl_Imprimir
        AddHandler BarBtnRefresh.ItemClick, AddressOf prl_Refresh
        AddHandler ConsultarViajeXTrabajador1.AdvBandedGridView1.CustomUnboundColumnData, AddressOf prl_CustomUnBoundColumnData
    End Sub

    Private Sub prl_CustomUnBoundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs)
        If e.Column.FieldName = "foto" Then
            Dim view As GridView = TryCast(sender, GridView)
            Const fileName As String = "User.png"
            If (Not Images.ContainsKey(fileName)) Then
                Dim img As Image = Nothing
                Try
                    Dim filePath As String = DevExpress.Utils.FilesHelper.FindingFileName("E:\SG_Control_Vuelos\Control_Vuelos_GUI\", ImageDir & fileName, False)
                    img = Image.FromFile(filePath)
                Catch
                End Try
                Images.Add(fileName, img)
            End If
            e.Value = Images(fileName)
        End If
    End Sub

    Private Sub prl_Refresh()
        ConsultarViajeXTrabajador1.GridControl1.DataSource = oPasajero.pr_Reservas.Tables("Pasajero")
    End Sub

    Private Sub prl_Imprimir()
        Using printingSystem1 As New PrintingSystem()
            printingSystem1.Links.AddRange(New Object() {printableComponentLink1})
        End Using
        printableComponentLink1.Landscape = True
        ConsultarViajeXTrabajador1.GridControl1.Refresh()
        printableComponentLink1.Component = ConsultarViajeXTrabajador1.GridControl1
        printableComponentLink1.ShowPreviewDialog()
    End Sub

    Private Sub printableComponentLink1_CreateReportHeaderArea(ByVal sender As Object, ByVal e As DevExpress.XtraPrinting.CreateAreaEventArgs) Handles printableComponentLink1.CreateReportHeaderArea
        Using brick As DevExpress.XtraPrinting.TextBrick = e.Graph.DrawString("Record de Viaje Por Persona", Color.Blue, New RectangleF(0, 0, 500, 40), DevExpress.XtraPrinting.BorderSide.None)
            brick.Font = New Font("Tahoma", 16)
            brick.StringFormat = New DevExpress.XtraPrinting.BrickStringFormat(StringAlignment.Center)
        End Using
    End Sub

End Class